#pragma once

#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <stdio.h>
#include <math.h>
#include <fstream>

#include "ResourceLibrary.h"

class ResourceLibrary;

using namespace cv;
using namespace std;

class ImageStitcher
{
public:

	//float	r, g, b;
	Mat grayscale1;
	Mat grayscale2;

	ResourceLibrary* resources;

	Mat descriptors_object;
	Mat descriptors_scene;

	vector< KeyPoint > keypoints_object;
	vector< KeyPoint > keypoints_scene;

	vector< DMatch > good_matches;

	vector< Point2f > obj;
	vector< Point2f > scene;

	vector< Point2f > obj_corners();
	vector< Point2f > scene_corners();

	vector< Mat > homographies;
	vector< vector< Point2f > > warped_corners;

	int largestX;
	int largestY;

	ImageStitcher(ResourceLibrary* rl);							//Constructor
	~ImageStitcher(void);

	//-- Drawing Functions
	void ImageStitcher::drawAllKeypoints(Mat img1, Mat img2);
	void ImageStitcher::drawGoodMatches(Mat img1, Mat img2, Mat img_matches);
	void ImageStitcher::showImage1and2(Mat img1, Mat img2);

	//-- Text Output Functions	
	void ImageStitcher::printCorners(vector<Point2f> corners);
	void ImageStitcher::printHomographyMatrix(Mat H);

	//-- Features Functions
	void ImageStitcher::extractFeatures();
	void ImageStitcher::matchFeatures();

	//-- Storage Functions
	void ImageStitcher::storeWarpedCorners(vector<Point2f> corners);
	void ImageStitcher::clearVectors();

	//-- Stitching Process Functions
	Mat ImageStitcher::stitchImages(Mat img1, Mat img2);
	Mat ImageStitcher::getHomographyMatrix(Mat img1,Mat img2);
	Mat ImageStitcher::warpImages(Mat img1,Mat img2, Mat H, vector<Point2f> obj_corners, vector<Point2f> scene_corners, double minX, double minY, int indexX, int indexY);
	
};
